package actionHandlers;

/*
 * Undo action handler, removes last entry from
 * the shapes array list and pushes it onto the stack
 * repaints
 */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import palette.CanvasManager;
import palette.CanvasWindow;
import undoRedo.UndoRedo;
import cuShapes.PQShape;

/*
 * @author: Daniel Miller
 */

public class UndoHandler implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent arg0) {
		List<PQShape> List = ((CanvasWindow)CanvasManager.getInst().getSelectedFrame()).getCanvas().getShapeList();
		UndoRedo undoStack = UndoRedo.getInst();
		if(List.size() > 0)
		{
			Object item = List.remove(List.size() - 1);
			undoStack.push(item);
			((CanvasWindow)CanvasManager.getInst().getSelectedFrame()).getCanvas().repaint();
		}
		((CanvasWindow)CanvasManager.getInst().getSelectedFrame()).getCanvas().repaint();
		
	}

}
